<?php

namespace app\api\controller\goods;

use app\api\BaseController;
use app\api\service\GoodsCategoryService;

class CategoryController extends BaseController
{

    public function index()
    {
        $store_id = $this->request->param('store_id/d');

        if (empty($store_id)) {
            return json(['code' => 0, 'msg' => '非法参数']);
        }

        $categories = GoodsCategoryService::getCategoryList($store_id);

        return json(['code' => 1, 'data' => $categories, 'msg' => '请求成功!']);
    }

    /**
     * 一级分类
     */
    public function categoryList()
    {
        $store_id = $this->request->param('store_id/d');
        if (empty($store_id)) {
            return json(['code' => 0, 'msg' => '非法参数']);
        }
        $categories = GoodsCategoryService::categoryList($store_id);
        return json(['code' => 1, 'data' => $categories, 'msg' => '请求成功!']);
    }

     /**
     * 二级分类
     */
    public function secondCategoryList()
    {
        $store_id = $this->request->param('store_id/d');
        if (empty($store_id)) {
            return json(['code' => 0, 'msg' => '非法参数']);
        }
        $cid = $this->request->param('cid/d');
        if (empty($cid)) {
            return json(['code' => 0, 'msg' => '非法参数']);
        }
        $categories = GoodsCategoryService::secondCategoryList($store_id, $cid);
        return json(['code' => 1, 'data' => $categories, 'msg' => '请求成功!']);
    }

    // /**
    //  * 根据二级分类查商品
    //  */
    // public function secondCateGoods()
    // {
    //     $store_id = $this->request->param('store_id/d');
    //     if (empty($store_id)) {
    //         return json(['code' => 0, 'msg' => '非法参数']);
    //     }
    //     $cid = $this->request->param('cid/d');
    //     if (empty($cid)) {
    //         return json(['code' => 0, 'msg' => '非法参数']);
    //     }
    //     $categories = GoodsCategoryService::secondCategoryList($store_id, $cid);
    //     return json(['code' => 1, 'data' => $categories, 'msg' => '请求成功!']);
    // }
}
